<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<html>
    <head>
        <title>Works Clup</title>
        <link href="public/css/style_web2.css" rel="stylesheet" type="text/css">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script type="text/javascript">
            function slideSwitch() {
                var $active = $('#baner IMG.active');
                if ($active.length == 0)
                    $active = $('#baner IMG:last');
                var $next = $active.next().length ? $active.next()
                        : $('#baner IMG:first');
                $active.addClass('last-active');
                $next.css({opacity: 0.0})
                        .addClass('active')
                        .animate({opacity: 1.0}, 1000, function() {
                    $active.removeClass('active last-active');
                });
            }
            $(function() {
                setInterval("slideSwitch()", 3000);
            });
            </script>
    </head>
    <body>
        <div id="wrapper">
            <?php
            require_once './model/works.php';
            require_once './model/users.php';
            $keyword = new Works();
            $keyword->table_name = "works";
            ?>
            <?php
            if (!isset($_GET["page"]))
                $page = 1;
            else
                $page = $_GET["page"];

            $total = $keyword->countWords();
            ?>
            <div id="sum">
                <div id="baner">
                    <img src="public/images/party-night-desktop-wallpaper-1080x300.jpg" width="100%" alt="" class ="active"/>
                </div>
                <div id="boder"></div>
                <header>

                    <div id="col_left">
                                             
                            <p class="main_menu">
                            
                        <h3>dang nhap</h3>
                        <div id="boder_menu"></div>
                        </p>
                        <form method="POST">
                            <p>User name</p>
                            <input type="text" name="username">
                            <p>Password <strong>*</strong></p>
                            <input type="password" name="password"></br>

                            <p id="input_st"><input type="submit" name="submit" value="Log in"></p>
                            <?php if (isset($_POST['submit'])): ?>
                            </form>
                            <?php
                            $username = $_POST['username'];
                            $password = $_POST['password'];
                            $Ok = FALSE;
                            $index = -1;
                            for ($i = 0; $i < count($users); $i++) {
                                if ((strcmp($users[$i]['username'], $username) == 0) &&
                                        (strcmp($users[$i]['password'], $password) == 0)) {
                                    $Ok = TRUE;
                                    $index = $i;
                                }
                            }
                            if ($Ok) {
                                header("Location: http://localhost/hyphi-web2/index.php?uid=" . $users[$index]["id"]);
                            } else {
                                echo "Đăng nhập thất bại";
                            }
                            ?>
                        <?php endif; ?>
                        <a href ="login_1.php?logout=true"><h3 align ="left">logout</h3></a>
                    </div>
                    <section>
                        <p class="main_menus">
                            <nav>
                                <ul>
                                <li><a href ="index.php">trang chu</a></li>
                                <li><a href ="index.php">tin tuc</a></li>
                                <li><a href ="index.php">su kien</a></li>
                                <li><a href ="index.php">dia chi</a></li>
                                </ul>
</nav>
                       
                        </p>
 <div id="boder_menus"></div>
                                   <div class="noidung">
                <div class="nav" style="clear: both;"> 
                    <ul>
                        <?php if (!isset($_GET["page"])):
                            ?>

                            <a href="index.php?page=<?php echo $_GET['page'] = 1 ?>">
                            </a>
                        <?php endif; ?>


                        <li> <a href="index.php?page=1">Fist</a></li>
                        <li><a href="index.php?page=<?php echo $_GET["page"] - 1 ?>"><< Prev</a></li>

                        <?php for ($i = 1; $i <= 7; $i++): ?>
                            <?php if (($_GET["page"] == 1) || ($_GET["page"] == 2) || ($_GET["page"] == 3) || ($_GET["page"] == 4)): ?>            
                                <?php for ($i = 1; $i <= 7; $i++): ?>
                                    <li><a href='index.php?page=<?php echo $i; ?> '><?php echo $i ?></a></li>
                                    <?php if ($_GET["page"] == $i): ?>
                                        <?php $keyword->begin; ?>
                                        <?php $keyword->theend = PAGE; ?>
                                    <?php endif; ?>
                                <?php endfor; ?>
                            <?php elseif (($_GET["page"] == $total / PAGE) || ($_GET["page"] == $total / PAGE - 1) || ($_GET["page"] == $total / PAGE - 2) || ($_GET["page"] == $total / PAGE - 3)): ?>        
                                <?php for ($i = $total / PAGE - 7; $i <= $total / PAGE; $i++): ?>
                                    <li><a href='index.php?page=<?php echo $i; ?> '><?php echo $i ?></a></li>
                                    <?php if ($_GET["page"] == $i): ?>
                                        <?php $keyword->begin; ?>
                                        <?php $keyword->theend = PAGE; ?>
                                    <?php endif; ?>
                                <?php endfor; ?>
                            <?php else : ?>
                                <?php for ($i = $_GET["page"] - 3; $i <= $_GET["page"] + 3; $i++): ?>
                                    <li><a href='index.php?page=<?php echo $i; ?> '><?php echo $i ?></a></li>
                                    <?php if ($_GET["page"] == $i): ?>
                                        <?php $keyword->begin; ?>
                                        <?php $keyword->theend = PAGE; ?>
                                    <?php endif; ?>
                                <?php endfor; ?>
                            <?php endif; ?> 
                        <?php endfor; ?>
                        <li><a href="index.php?page=<?php echo $_GET['page'] + 1 ?>">Next >></a></li>           
                        <li><a href="index.php?page=<?php echo $total / PAGE ?>">Last</a></li>
                      
                        <?php $keywords = $keyword->select($page); ?>
                    </ul>
                </div>
                        <?php if (!isset($_GET["page"])):
                            ?>

                            <a href="index.php?page=<?php echo $_GET['page'] = 1 ?>">
                            </a>
                        <?php endif; ?>
                        <table border="1px" style="clear: both;" class="nd">
                    <tr  id="tr" >
                        
                        <td>Name</td>
                        <td>Images</td>
                        <td>Description</td>
                        
                    </tr>
                    <?php foreach ($keywords as $keywordss): ?>
                        <tr class="b">
                            
                            <td><a href='<?php echo $keywordss['url'];?> '> <?php echo $keywordss['name']; ?></td>
                            <td><img src="<?php echo $keywordss['image'] ?>" with="100px" height="100px"></td>
                            <td><?php echo substr($keywordss['description'], 0, 200); ?></td>
                            <?php if (isset($_GET['uid'])): ?>                         <?php if ((int) $_GET['uid'] == 0): ?> 
                            <td><image src="public/images/notes_edit.png" width="20px" heigth="20px"><a href="edit.php?id=<?php echo $keywordss['id']; ?>">Edit</a>
                            <image src="public/images/das.png" width="20px" heigth="320px"><a href="submit.php?id=<?php echo $keywordss['id']; ?>">View</a>
                            <image src="public/images/full-recycle-bin.png" width="20px" heigth="20px"><a href="submit.php?id=<?php echo $keywordss['id'], 0, 100; ?>">Delete</a>
                            </td>
                            <?php else: ?>
                            <td>
                        <image src="public/images/das.png" width="20px" heigth="320px"><a href="submit.php?id=<?php echo $keywordss['id']; ?>">View</a></td>
                                <?php endif; ?>
                            <?php endif; ?>
                        </tr>
                    <?php endforeach; ?>
                </table>
                        
                    </section>
                </header>

                <div class="clear"></div>
                <div id="boder"></div>
                <footer>
                    <p class="colleft">
                    <table class="o">
                        <tr>
                            <div> <h2 align="center" ></h2></div></tr>
                    </table>
                    </p>
                    <p class="colright">
                    <table class="colright">
                        <tr>
                            <td></td><td>CONTACT</td></tr>
                        <tr><td></td><td>TRƯỜNG CAO ĐẲNG CÔNG NGHỆ THỦ ĐỨC</td></tr>
                        <tr> <td></td><td>Proudly powered by Drupal. Designed by C12TDT Works</td></tr>
                    </table>
                    </p>
                </footer>
            </div>
        </div>
    </body>
</html>
